package org.sample.springbootrabbitmq.queue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MessageSender {

	private static final Logger LOGGER = LoggerFactory.getLogger(MessageSender.class);

	@Autowired
	private RabbitTemplate rabbitTemplate;

	@Autowired
	private Queue textQueue;

	@Autowired
	private Exchange userEventExchange;

	@Autowired
	private Exchange itemEventExchange;

	public void sendText(String message) {
		rabbitTemplate.convertAndSend(textQueue.getName(), message);
		LOGGER.info("Sent text: {}", message);
	}

	public void sendUserEvent(String message) {
		rabbitTemplate.convertAndSend(userEventExchange.getName(), "user.create", message);
		LOGGER.info("Sent user event: {}", message);
	}

	public void sendItemEvent(String message) {
		rabbitTemplate.convertAndSend(itemEventExchange.getName(), "item.create", message);
		LOGGER.info("Sent item event: {}", message);
	}

}
